local CountCondition = class("CountCondition")

function CountCondition:ctor(eventId, condition)
    self._condition = condition
    self._count = 0
    self._signal = G_SignalManager:add(eventId, handler(self, self._onEvent))
end

function CountCondition:_onEvent(id, ...)
    self._count = self._count + 1
    if self._condition(self._count, ...) then
        self:remove()
    end
end

function CountCondition:remove()
    self._signal:remove()
    self._signal = nil
end

return CountCondition
